<?php
    $top_menu_1 = FALSE;
    $top_menu_2 = FALSE;
    $top_menu_3 = FALSE;
    $top_menu_4 = FALSE;
    $top_menu_5 = FALSE;
    $top_menu_6 = TRUE;
    $top_menu_7 = FALSE;
    include('header.php');
    include('sidebar2.php');
    
    if(!isset($_SESSION['m_id'])){
	$class1 = ' class="display_none"';
	$class2 = '';
	$class3 = ' class="display_none"';
    }else{
	$class1 = '';
	$class2 = ' class="display_none"';
	$class3 = ' class="display_none"';
	
	if(isset($_GET['id'])){
		$p_name = $db->queryUniqueValue('SELECT p_name FROM hs_product WHERE p_id='.$_GET['id']);
		$p_cart = $db->queryUniqueValue('SELECT p_id FROM hs_cart WHERE p_id='.$_GET['id'].' AND m_id='.$_SESSION['m_id']);
		
		if($p_cart=='' OR $p_cart==NULL){
		    $rss = $db->query('INSERT INTO hs_cart(m_id,p_id,p_name,date_add) VALUES('.$_SESSION['m_id'].' , '.$_GET['id'].' , "'.$p_name.'" , NOW() )');
		}
	}
	
	$rss = $db->query('SELECT * FROM hs_cart WHERE m_id='.$_SESSION['m_id'].' GROUP BY p_id');
	$cart_list = '';
	while ($line = $db->fetchNextObject($rss)){
		
		$img = $db->queryUniqueValue('SELECT p_img FROM hs_product WHERE p_id='.$line->p_id);
		
		if($img!='' AND file_exists(APPPATH.'/images/products/product/'.$line->p_id.'/'.$img)){
		    $productImg = URL.'/images/products/product/'.$line->p_id.'/'.$img;
		}else{
		    $productImg = URL.'/images/noimg.jpg';
		}
		$cart_list .= <<<cart_list
		<tr>
			<td class="td1"><img src="{$productImg}" alt="{$line->p_name}" /></td>
			<td class="td2">{$line->p_name}</td>
			<td class="td3"><input type="hidden" name="pid[]" value="{$line->p_id}" /><input type="text" name="pq[{$line->p_id}]" value="1" /> <img src="images/order_delete_bt.jpg" alt="Delete" class="img_link delete_item" id="{$line->p_id}" /><img src="images/ajax-loader.gif" id="ajax_loader_{$line->p_id}" class="display_none" /></td>
		</tr>
		<tr>
			<td colspan="3" class="order_line"><img src="images/order_line.jpg" /></td>
		</tr>
cart_list;
	}
	
	if($cart_list==''){
		$class1 = ' class="display_none"';
		$class2 = ' class="display_none"';
		$class3 = '';
	}
    }
?>
            <div id="main_content" class="order_content">
                <img src="images/order_title.jpg" alt="Order" id="order_title" />
                <div id="oder_detail" <?php echo $class1; ?>>
                    Select any items you like and sumit for quotation. Your account merchandiser will contact you within 24 hours with pricing. Any special request please note in the Requirement section. Thnak you
                </div>
                <form id="qoute_frm">
                <table id="order_list" <?php echo $class1; ?>>
                    <tr>
                        <td colspan="3"><img src="images/order_list_header.jpg" /></td>
                    </tr>
                    
                    <?php echo $cart_list; ?>
                    
                    <tr>
                        <td colspan="3">
                            <div id="order_msg">
                                <label>Requirement :</label>
                                <textarea id="requirement" name="requirement"></textarea>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3" id="order_bt">
                            <img src="images/order_continue.jpg" alt="Continue Shopping" class="img_link" id="continue_bt" />
                            <a href="images/ajax-loader.gif" class="ajax_loader"><img src="images/order_qoute.jpg" alt="Qoute Now" class="img_link" id="qoute_bt" /></a>
                        </td>
                    </tr>
                </table>
		</form>
		<div id="oder_error_msg" <?php echo $class2; ?>>
                   <?php echo $status_msg['must_login']; ?>
                </div>
		<div id="oder_error_msg" <?php echo $class3; ?>>
                   <?php echo $status_msg['cart_empty']; ?>
                </div>
                    
                <div class="clear">&nbsp;</div>
            </div>
            <div class="clear">&nbsp;</div>
<?php
    include('footer.php');
?>
<script>
	$(document).ready(function() {
		$("a.ajax_loader").fancybox({
			'speedIn'		:	600, 
			'speedOut'		:	200, 
			'titleShow'	:	false,
			'opacity' : true,
			'padding' : 0,
			'margin' : 0,
			'showCloseButton' : false
		});
		
		$('#continue_bt').live('click',function(){
		    window.location = 'product.php';
		});
		
		$('#qoute_bt').live('click',function(){
		    str = $('#qoute_frm').serialize();
		    
		    $.post('function/qoute.php',str,function(data){
			if(data.status=='success'){
				alert(data.msg);
				$.post("function/query_cart_clear.php",'',function(data){
					window.location = 'index.php';
				});
			}else{
				alert(data.msg);
				location.reload();
			}
		    },'json');
		});
		
		$('.delete_item').live('click',function(){
		    pid = $(this).attr('id');
		    $(this).css('display','none');
		    $('#ajax_loader_'+pid).css('display','inline');
		    $.post('function/cart_delete_product.php','pid='+pid,function(data){
			if(data.status=='success'){
				location.reload();
			}else{
				$('#ajax_loader_'+pid).css('display','none');
				$(this).css('display','inline');
				alert(data.msg);
			}
		    },'json');
		});
	});
</script>